[#include "../../../common/html.ftl" /]
[@html]
    [@head title="组织机构部门列表" css=["fw", "bootstrap-treetable"] /]
    [@body]
        [#--主体内容--]
        [@main ]
            <div class="am-g am-radius fw-tables">
                [#--表格主体内容--操作栏--]
                [@mainHeader]
                    [#--[@shiro.hasPermission name="system:dept:add"]--]
                    <button class="am-btn am-btn-success am-radius" onclick="$.operate.addFull(0)">添加</button>
                    [#--[/@shiro.hasPermission]--]
                    [#--[@shiro.hasPermission name="system:dept:export"]--]
                    [#--<button class="am-btn am-btn-warning am-radius" onclick="$.table.exportExcel()">导出</button>--]
                    [#--[/@shiro.hasPermission]--]
                    <button class="am-btn am-btn-black am-radius" id="expandAllBtn">展开/折叠</button>
                [/@mainHeader]

                [#--表格主体内容--搜索栏--]
                [@searchForm searchId="form-dept-search" searchFun="$.treeTable.search()"]
                    <div class="am-form-group">
                        <input class="am-form-field am-input-sm am-radius" type="text" name="deptName" placeholder="机构/部门名称">
                    </div>
                    <div class="am-form-group">
                        <select class="am-radius" name="status" data-am-selected placeholder="机构/部门状态">
                            <option value=""></option>
                            [#list dict.getType("sys_normal_disable") as dict]
                                <option value="${dict.dictValue}">${dict.dictLabel}</option>
                            [/#list]
                        </select>
                    </div>
                [/@searchForm]

                <div class="fw-table">
                    <table id="bootstrap-tree-table"></table>
                </div>
            </div>
        [/@main]

        [#--PC/APP 右侧悬浮按钮--]
        [@rightToolbar /]

        [@script js=["fw", "bootstrap-treetable"]]
            <script type="text/javascript">
                [#--var editFlag = "${hasPermission('system:dept:edit')}";--]
                [#--var addFlag = "${hasPermission('system:dept:add')}";--]
                [#--var removeFlag = "${hasPermission('system:dept:remove')}";--]
                var addFlag = "";
                var editFlag = "";
                var removeFlag ="";
                var datasDeptStatus = ${convert.toJson(dict.getType("sys_normal_disable"))};
                var isAdministrator = ${convert.toJson(common.isAdministrator())};

                var prefix = ctx + "osfw/system/manage/dept";

                $(function () {
                    var options = {
                        code: "deptId",
                        parentCode: "parentId",
                        uniqueId: "deptId",
                        expandColumn: 0,
                        expandAll: true,
                        expandFirst: false,
                        url: prefix + "/list",
                        createUrl: prefix + "/add/{id}",
                        updateUrl: prefix + "/edit/{id}",
                        removeUrl: prefix + "/remove/{id}",
                        exportUrl: prefix + "/export",
                        importUrl: prefix + "/importData",
                        importTemplateUrl: prefix + "/importTemplate",
                        downTemplate: ctx + "common/downTemplate?fileName=sys_dept.xls&realFileName=组织机构内设部门信息.xls",
                        modalName: "部门",
                        columns: [
                            {
                                field: 'deptName',
                                title: '机构/部门名称',
                                align: "left",
                                width: '30%',
                            },
                            {
                                field: 'status',
                                title: '部门状态',
                                align: "left",
                                formatter: function (value, item, index) {
                                    return $.table.selectDictLabel(datasDeptStatus, item.status);
                                }
                            },
                            {
                                field: 'leader',
                                title: '负责人',
                                align: "left",
                            },
                            {
                                field: 'phone',
                                title: '联系电话',
                                align: "left",
                            },
                            {
                                field: 'orderNum',
                                title: '显示排序'
                            },
                            {
                                title: '操作',
                                formatter: function (value, row, index) {
                                    var actions = [];
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.addFull(\'' + row.deptId + '\')">添加</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.deptId + '\')">编辑</a> ');
                                    actions.push('<a class="am-badge am-badge-transparent am-radius ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.deptId + '\')">删除</a> ');
                                    return actions.join('');
                                }
                            }
                        ]
                    };
                    $.treeTable.init(options);
                });


            </script>
        [/@script]
    [/@body]
[/@html]
